/**
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package us.levk.tools.collections;

import java.util.AbstractMap;
import java.util.Map;
import java.util.Set;


/**
 * <p>A Map wrapper that does not support destructive operations</p>
 * 
 * <p>put() method will raise an IllegalArgumentException on an already bound key</p>
 * 
 * @author levk
 *
 */
public class NonDestructiveMap<K, V> extends AbstractMap<K, V> {

  private final Map<K, V> wrapped;

  public NonDestructiveMap (Map<K, V> wrapped) { this.wrapped = wrapped; }

  /* (non-Javadoc)
   * @see java.util.AbstractMap#entrySet()
   */
  @Override public Set<Entry<K, V>> entrySet () {
    return new NonDestructiveSet<Entry<K, V>> (wrapped.entrySet ());
  }

  /* (non-Javadoc)
   * @see java.util.AbstractMap#put(java.lang.Object, java.lang.Object)
   */
  @Override public V put (K key, V value) {
    if (wrapped.containsKey (key)) throw new IllegalArgumentException ();
    else return wrapped.put (key, value);
  }
}
